<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book python高级 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>数据完整性 | python高级</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../day14/03.Navicat.html" />
    
    
    <link rel="prev" href="../day14/01.数据库概述.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="4.2"
        data-chapter-title="数据完整性"
        data-filepath="day14/02.数据类型和约束.md"
        data-basepath=".."
        data-revision="Wed Sep 26 2018 22:46:13 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Python高级
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="day11/00.readme.html">
            
                
                    <a href="../day11/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Python语法高级专题1
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="day11/01.GIL.html">
            
                
                    <a href="../day11/01.GIL.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        GIL问题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="day11/02.copy.html">
            
                
                    <a href="../day11/02.copy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        赋值-浅拷贝-深拷贝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="day11/03.import.html">
            
                
                    <a href="../day11/03.import.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        import导入模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="day11/04.review.html">
            
                
                    <a href="../day11/04.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="day12/00.readme.html">
            
                
                    <a href="../day12/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        Python语法高级专题2
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="day12/01.mro.html">
            
                
                    <a href="../day12/01.mro.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        多继承和MRO顺序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="day12/02.property.html">
            
                
                    <a href="../day12/02.property.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        property属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="day12/03.magic.html">
            
                
                    <a href="../day12/03.magic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        魔法属性和方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="day12/04.with.html">
            
                
                    <a href="../day12/04.with.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        with管理上下文
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="day12/05.review.html">
            
                
                    <a href="../day12/05.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="day13/00.readme.html">
            
                
                    <a href="../day13/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Python语法之装饰器
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="day13/01.closure.html">
            
                
                    <a href="../day13/01.closure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        闭包
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="day13/02.decorator.html">
            
                
                    <a href="../day13/02.decorator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="day13/03.review.html">
            
                
                    <a href="../day13/03.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="day14/00.readme.html">
            
                
                    <a href="../day14/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        MySQL数据库基本操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="day14/01.数据库概述.html">
            
                
                    <a href="../day14/01.数据库概述.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        数据库概述
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="4.2" data-path="day14/02.数据类型和约束.html">
            
                
                    <a href="../day14/02.数据类型和约束.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        数据完整性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="day14/03.Navicat.html">
            
                
                    <a href="../day14/03.Navicat.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        图形化客户端Navicat
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="day14/04.命令行客户端.html">
            
                
                    <a href="../day14/04.命令行客户端.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        命令行客户端SQL的使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.1" data-path="day14/05.sql_con.html">
            
                
                    <a href="../day14/05.sql_con.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.1.</b>
                        
                        登录和退出数据库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.2" data-path="day14/07.sql_table_struct.html">
            
                
                    <a href="../day14/07.sql_table_struct.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.2.</b>
                        
                        表结构的操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.3" data-path="day14/06.sql_database.html">
            
                
                    <a href="../day14/06.sql_database.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.3.</b>
                        
                        数据库的操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.4" data-path="day14/08.表数据操作.html">
            
                
                    <a href="../day14/08.表数据操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.4.</b>
                        
                        表数据的操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="day14/09.review.html">
            
                
                    <a href="../day14/09.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        知识总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="day15/00.readme.html">
            
                
                    <a href="../day15/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        MYSQL数据库进阶操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="day15/01.练习.html">
            
                
                    <a href="../day15/01.练习.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        练习强化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="day15/02.where条件.html">
            
                
                    <a href="../day15/02.where条件.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        条件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="day15/03.排序查询.html">
            
                
                    <a href="../day15/03.排序查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="day15/04.分页查询.html">
            
                
                    <a href="../day15/04.分页查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        分页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="day15/05.聚合函数.html">
            
                
                    <a href="../day15/05.聚合函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        聚合函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="day15/06.分组.html">
            
                
                    <a href="../day15/06.分组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        分组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="day15/07.连接.html">
            
                
                    <a href="../day15/07.连接.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="day15/08.自连接.html">
            
                
                    <a href="../day15/08.自连接.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        自连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="day15/09.子查询.html">
            
                
                    <a href="../day15/09.子查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        子查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="day15/10.总结.html">
            
                
                    <a href="../day15/10.总结.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="day16/readme.html">
            
                
                    <a href="../day16/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        MYSQL数据库编程
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="day16/data.html">
            
                
                    <a href="../day16/data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        数据准备
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="day16/sql_code.html">
            
                
                    <a href="../day16/sql_code.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        SQL演练
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="day16/dbdesign.html">
            
                
                    <a href="../day16/dbdesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="day16/pymysql.html">
            
                
                    <a href="../day16/pymysql.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        数据库编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="day16/zongjie.html">
            
                
                    <a href="../day16/zongjie.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="day17/00.readme.html">
            
                
                    <a href="../day17/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        MySQL数据库高级用法
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="day17/01.view.html">
            
                
                    <a href="../day17/01.view.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="day17/02.transaction.html">
            
                
                    <a href="../day17/02.transaction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        事务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="day17/03.sql_index.html">
            
                
                    <a href="../day17/03.sql_index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        索引
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="day17/04.user.html">
            
                
                    <a href="../day17/04.user.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        用户管理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="day17/05.master_slave.html">
            
                
                    <a href="../day17/05.master_slave.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        主从配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="day17/06.review.html">
            
                
                    <a href="../day17/06.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        总结
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="day18/00.readme.html">
            
                
                    <a href="../day18/00.readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        miniweb框架
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="day18/01.框架是什么.html">
            
                
                    <a href="../day18/01.框架是什么.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        框架概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="day18/02.实现框架.html">
            
                
                    <a href="../day18/02.实现框架.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        实现一个简单的框架
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="day18/03.模板.html">
            
                
                    <a href="../day18/03.模板.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        模板替换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="day18/04.路由.html">
            
                
                    <a href="../day18/04.路由.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        路由概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="day18/05.显示股票数据.html">
            
                
                    <a href="../day18/05.显示股票数据.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        股票收藏夹
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="day18/05.review.html">
            
                
                    <a href="../day18/05.review.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        复习
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >python高级</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="2-&#x6570;&#x636E;&#x7C7B;&#x578B;&#x548C;&#x7EA6;&#x675F;">2. &#x6570;&#x636E;&#x7C7B;&#x578B;&#x548C;&#x7EA6;&#x675F;</h1>
<p><strong>&#x5B66;&#x4E60;&#x76EE;&#x6807;</strong></p>
<ol>
<li>MySQL &#x6570;&#x636E;&#x5E93;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x4F5C;&#x7528;</li>
<li>MySQL &#x6570;&#x636E;&#x5E93;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x6709;&#x54EA;&#x4E9B;</li>
<li>MySQL &#x6570;&#x636E;&#x5E93;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x9009;&#x62E9;</li>
<li>MySQL &#x6570;&#x636E;&#x5E93;&#x7EA6;&#x675F;&#x7684;&#x4F5C;&#x7528;</li>
<li>MySQL &#x6570;&#x636E;&#x5E93;&#x7C7B;&#x578B;&#x7EA6;&#x675F;&#x6709;&#x54EA;&#x4E9B;</li>
</ol>
<hr>
<blockquote>
<p>&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x5B58;&#x50A8;&#x7684;&#x6570;&#x636E;&#x5E94;&#x8BE5;&#x7B26;&#x5408;&#x6211;&#x4EEC;&#x7684;&#x9884;&#x671F;, &#x8FD9;&#x5C31;&#x662F;&#x6570;&#x636E;&#x5B8C;&#x6574;&#x6027;. &#x90A3;&#x4E48;&#x5982;&#x4F55;&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x5B8C;&#x6574;&#x6027;?</p>
</blockquote>
<p>&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x4EE5;&#x4E0B;&#x4E24;&#x65B9;&#x9762;&#x6765;&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x7684;&#x5B8C;&#x6574;&#x6027;.</p>
<ol>
<li>&#x6570;&#x636E;&#x7C7B;&#x578B;: &#x5B58;&#x50A8;&#x5728;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x6570;&#x636E;&#x503C;&#x5747;&#x6B63;&#x786E;&#x7684;&#x72B6;&#x6001;&#x3002;&#x5982;&#x679C;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x5B58;&#x50A8;&#x6709;&#x4E0D;&#x6B63;&#x786E;&#x7684;&#x6570;&#x636E;&#x503C;&#xFF0C;&#x5219;&#x8BE5;&#x6570;&#x636E;&#x5E93;&#x79F0;&#x4E3A;&#x5DF2;&#x4E27;&#x5931;&#x6570;&#x636E;&#x5B8C;&#x6574;&#x6027;&#x3002;</li>
<li>&#x6570;&#x636E;&#x7EA6;&#x675F;: &#x5728;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x9650;&#x5B9A;&#x7684;&#x57FA;&#x7840;&#x4E0A;, &#x6DFB;&#x52A0;&#x7684;&#x989D;&#x5916;&#x7684;&#x8981;&#x6C42;.</li>
</ol>
<h2 id="21-&#x6570;&#x636E;&#x7C7B;&#x578B;">2.1 &#x6570;&#x636E;&#x7C7B;&#x578B;</h2>
<p>&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5F71;&#x54CD;&#x7740;&#x6570;&#x636E;&#x4E2D;&#x5B58;&#x50A8;&#x7684;&#x6570;&#x636E;&#x6240;&#x5360;&#x7684;&#x7C7B;&#x578B;&#x7EA6;&#x675F;&#x3001;&#x7A7A;&#x95F4;&#x5927;&#x5C0F;.</p>
<ul>
<li>&#x53EA;&#x6709;&#x7C7B;&#x578B;&#x7B26;&#x5408;&#x8981;&#x6C42;&#x7684;&#x6570;&#x636E;&#x624D;&#x80FD;&#x5B58;&#x50A8;&#x8D77;&#x6765; &#x8FD9;&#x5C31;&#x662F;&#x5BF9;&#x6570;&#x636E;&#x5B8C;&#x6574;&#x6027;&#x7684;&#x4E00;&#x79CD;&#x8981;&#x6C42;.</li>
<li>&#x4F7F;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x539F;&#x5219;&#x662F;:&#x591F;&#x7528;&#x5C31;&#x884C;&#xFF0C;&#x5C3D;&#x91CF;&#x4F7F;&#x7528;&#x53D6;&#x503C;&#x8303;&#x56F4;&#x5C0F;&#x7684;&#xFF0C;&#x800C;&#x4E0D;&#x7528;&#x5927;&#x7684;&#xFF0C;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x66F4;&#x591A;&#x7684;&#x8282;&#x7701;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;</li>
</ul>
<p><strong>&#x5E38;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5982;&#x4E0B;:</strong></p>
<ul>
<li>&#x6574;&#x6570;&#xFF1A;int&#xFF0C;bit</li>
<li>&#x5C0F;&#x6570;&#xFF1A;decimal</li>
<li>&#x5B57;&#x7B26;&#x4E32;&#xFF1A;varchar,char</li>
<li>&#x65E5;&#x671F;&#x65F6;&#x95F4;: date, time, datetime</li>
<li>&#x679A;&#x4E3E;&#x7C7B;&#x578B;(enum)</li>
</ul>
<p><strong>&#x7279;&#x522B;&#x8BF4;&#x660E;&#x7684;&#x7C7B;&#x578B;&#x5982;&#x4E0B;&#xFF1A;</strong></p>
<ul>
<li>decimal&#x8868;&#x793A;&#x6D6E;&#x70B9;&#x6570;&#xFF0C;&#x5982; decimal(5, 2) &#x8868;&#x793A;&#x5171;&#x5B58;5&#x4F4D;&#x6570;&#xFF0C;&#x5C0F;&#x6570;&#x5360; 2 &#x4F4D;.</li>
<li>char&#x8868;&#x793A;&#x56FA;&#x5B9A;&#x957F;&#x5EA6;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5982;char(3)&#xFF0C;&#x5982;&#x679C;&#x586B;&#x5145;&apos;ab&apos;&#x65F6;&#x4F1A;&#x8865;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#x4E3A;<code>&apos;ab &apos;</code>.</li>
<li>varchar&#x8868;&#x793A;&#x53EF;&#x53D8;&#x957F;&#x5EA6;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5982;varchar(3)&#xFF0C;&#x586B;&#x5145;&apos;ab&apos;&#x65F6;&#x5C31;&#x4F1A;&#x5B58;&#x50A8;&apos;ab&apos;</li>
<li>&#x5BF9;&#x4E8E;&#x56FE;&#x7247;&#x3001;&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;&#x7B49;&#x6587;&#x4EF6;&#xFF0C;&#x4E0D;&#x5B58;&#x50A8;&#x5728;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#xFF0C;&#x800C;&#x662F;&#x4E0A;&#x4F20;&#x5230;&#x67D0;&#x4E2A;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x8868;&#x4E2D;&#x5B58;&#x50A8;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x7684;&#x4FDD;&#x5B58;&#x8DEF;&#x5F84;.</li>
<li>&#x5B57;&#x7B26;&#x4E32; text &#x8868;&#x793A;&#x5B58;&#x50A8;&#x5927;&#x6587;&#x672C;&#xFF0C;&#x5F53;&#x5B57;&#x7B26;&#x5927;&#x4E8E; 4000 &#x65F6;&#x63A8;&#x8350;&#x4F7F;&#x7528;, &#x6BD4;&#x5982;&#x6280;&#x672F;&#x535A;&#x5BA2;.</li>
</ul>
<p><a href="https://dev.mysql.com/doc/refman/5.7/en/data-type-overview.html" target="_blank">MySQL&#x4E2D;&#x5173;&#x4E8E;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x5B98;&#x65B9;&#x6587;&#x6863;</a></p>
<blockquote>
<p>&#x95EE;&#x9898;: &#x4EBA;&#x4E0E;&#x4EBA;&#x4E4B;&#x95F4;&#x7684;&#x8DDD;&#x79BB;&#x3001;&#x4EBA;&#x7684;&#x8EAB;&#x9AD8;&#x3001;&#x5E74;&#x9F84;&#x3001;&#x9A6C;&#x4E91;&#x7238;&#x7238;&#x7684;&#x94B1;&#x7528;&#x4EC0;&#x4E48;&#x7C7B;&#x578B;&#x6765;&#x5B58;&#x50A8;?</p>
</blockquote>
<h3 id="22-&#x6570;&#x636E;&#x7EA6;&#x675F;">2.2 &#x6570;&#x636E;&#x7EA6;&#x675F;</h3>
<p>&#x7EA6;&#x675F;&#x672C;&#x8D28;&#x4E0A;&#x662F;&#x5BF9;&#x6570;&#x636E;&#x5728;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x9650;&#x5B9A;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x6DFB;&#x52A0;&#x7684;&#x989D;&#x5916;&#x7684;&#x8981;&#x6C42;.</p>
<p>&#x5E38;&#x89C1;&#x7684;&#x7EA6;&#x675F;&#x5982;&#x4E0B;:</p>
<ol>
<li>&#x4E3B;&#x952E; primary key: &#x7269;&#x7406;&#x4E0A;&#x5B58;&#x50A8;&#x7684;&#x987A;&#x5E8F;. MySQL &#x5EFA;&#x8BAE;&#x6240;&#x6709;&#x8868;&#x7684;&#x4E3B;&#x952E;&#x5B57;&#x6BB5;&#x90FD;&#x53EB; id, &#x7C7B;&#x578B;&#x4E3A; int unsigned.</li>
<li>&#x975E;&#x7A7A; not null: &#x6B64;&#x5B57;&#x6BB5;&#x4E0D;&#x5141;&#x8BB8;&#x586B;&#x5199;&#x7A7A;&#x503C;.</li>
<li>&#x60DF;&#x4E00; unique: &#x6B64;&#x5B57;&#x6BB5;&#x7684;&#x503C;&#x4E0D;&#x5141;&#x8BB8;&#x91CD;&#x590D;.</li>
<li>&#x9ED8;&#x8BA4; default: &#x5F53;&#x4E0D;&#x586B;&#x5199;&#x5B57;&#x6BB5;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x4F1A;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x5982;&#x679C;&#x586B;&#x5199;&#x65F6;&#x4EE5;&#x586B;&#x5199;&#x4E3A;&#x51C6;.</li>
<li>&#x5916;&#x952E; foreign key: &#x5BF9;&#x5173;&#x7CFB;&#x5B57;&#x6BB5;&#x8FDB;&#x884C;&#x7EA6;&#x675F;, &#x5F53;&#x4E3A;&#x5173;&#x7CFB;&#x5B57;&#x6BB5;&#x586B;&#x5199;&#x503C;&#x65F6;, &#x4F1A;&#x5230;&#x5173;&#x8054;&#x7684;&#x8868;&#x4E2D;&#x67E5;&#x8BE2;&#x6B64;&#x503C;&#x662F;&#x5426;&#x5B58;&#x5728;, &#x5982;&#x679C;&#x5B58;&#x5728;&#x5219;&#x586B;&#x5199;&#x6210;&#x529F;, &#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x586B;&#x5199;&#x5931;&#x8D25;&#x5E76;&#x629B;&#x51FA;&#x5F02;&#x5E38;.</li>
</ol>
<p>&#x8BF4;&#x660E;&#xFF1A;&#x867D;&#x7136;<strong>&#x5916;&#x952E;</strong>&#x7EA6;&#x675F;&#x53EF;&#x4EE5;&#x4FDD;&#x8BC1;&#x6570;&#x636E;&#x7684;&#x6709;&#x6548;&#x6027;, &#x5728;&#x8FDB;&#x884C;&#x6570;&#x636E;&#x7684; crud, &#x4F1A;&#x964D;&#x4F4E;&#x6570;&#x636E;&#x5E93;&#x7684;&#x6027;&#x80FD;, &#x6B64;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;, &#x90A3;&#x4E48;&#x6570;&#x636E;&#x7684;&#x6709;&#x6548;&#x6027;&#x600E;&#x4E48;&#x4FDD;&#x8BC1;&#x5462;? </p>
<p>&#x53EF;&#x4EE5;&#x4ECE;&#x4EE3;&#x7801;&#x7F16;&#x5199;&#x4E2D;&#x8FDB;&#x884C;&#x63A7;&#x5236;. &#x5916;&#x952E;&#x8BE6;&#x7EC6;&#x7528;&#x6CD5;&#x5728;&#x7B2C;&#x4E09;&#x5929;&#x6570;&#x636E;&#x5E93;&#x8BFE;&#x7A0B;&#x4E2D;</p>
<h3 id="23-&#x6570;&#x636E;&#x7C7B;&#x578B;&#x9644;&#x5F55;&#x8868;">2.3 &#x6570;&#x636E;&#x7C7B;&#x578B;&#x9644;&#x5F55;&#x8868;</h3>
<h5 id="1-&#x6574;&#x6570;&#x7C7B;&#x578B;">1. &#x6574;&#x6570;&#x7C7B;&#x578B;</h5>
<table>
<thead>
<tr>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x5B57;&#x8282;&#x5927;&#x5C0F;</th>
<th style="text-align:left">&#x6709;&#x7B26;&#x53F7;&#x8303;&#x56F4;(Signed)</th>
<th style="text-align:left">&#x65E0;&#x7B26;&#x53F7;&#x8303;&#x56F4;(Unsigned)</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">TINYINT</td>
<td style="text-align:left">1</td>
<td style="text-align:left">-128 ~ 127</td>
<td style="text-align:left">0 ~ 255</td>
</tr>
<tr>
<td style="text-align:left">SMALLINT</td>
<td style="text-align:left">2</td>
<td style="text-align:left">-32768 ~ 32767</td>
<td style="text-align:left">0 ~ 65535</td>
</tr>
<tr>
<td style="text-align:left">MEDIUMINT</td>
<td style="text-align:left">3</td>
<td style="text-align:left">-8388608 ~ 8388607</td>
<td style="text-align:left">0 ~ 16777215</td>
</tr>
<tr>
<td style="text-align:left">INT/INTEGER</td>
<td style="text-align:left">4</td>
<td style="text-align:left">-2147483648 ~2147483647</td>
<td style="text-align:left">0 ~ 4294967295</td>
</tr>
<tr>
<td style="text-align:left">BIGINT</td>
<td style="text-align:left">8</td>
<td style="text-align:left">-9223372036854775808 ~ 9223372036854775807</td>
<td style="text-align:left">0 ~ 18446744073709551615</td>
</tr>
</tbody>
</table>
<h5 id="2-&#x5B57;&#x7B26;&#x4E32;">2. &#x5B57;&#x7B26;&#x4E32;</h5>
<table>
<thead>
<tr>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x5B57;&#x8282;&#x5927;&#x5C0F;</th>
<th style="text-align:left">&#x793A;&#x4F8B;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">CHAR</td>
<td style="text-align:left">0-255</td>
<td style="text-align:left">&#x7C7B;&#x578B;:char(3) &#x8F93;&#x5165; &apos;ab&apos;, &#x5B9E;&#x9645;&#x5B58;&#x50A8;&#x4E3A;&apos;ab &apos;,                                                                  &#x8F93;&#x5165;&apos;abcd&apos; &#x5B9E;&#x9645;&#x5B58;&#x50A8;&#x4E3A; &apos;abc&apos;</td>
</tr>
<tr>
<td style="text-align:left">VARCHAR</td>
<td style="text-align:left">0-255</td>
<td style="text-align:left">&#x7C7B;&#x578B;:varchar(3)  &#x8F93; &apos;ab&apos;,&#x5B9E;&#x9645;&#x5B58;&#x50A8;&#x4E3A;&apos;ab&apos;,                                                                 &#x8F93;&#x5165;&apos;abcd&apos;,&#x5B9E;&#x9645;&#x5B58;&#x50A8;&#x4E3A;&apos;abc&apos;</td>
</tr>
<tr>
<td style="text-align:left">TEXT</td>
<td style="text-align:left">0-65535</td>
<td style="text-align:left">&#x5927;&#x6587;&#x672C;</td>
</tr>
</tbody>
</table>
<h5 id="3-&#x65E5;&#x671F;&#x65F6;&#x95F4;&#x7C7B;&#x578B;">3. &#x65E5;&#x671F;&#x65F6;&#x95F4;&#x7C7B;&#x578B;</h5>
<table>
<thead>
<tr>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x5B57;&#x8282;&#x5927;&#x5C0F;</th>
<th style="text-align:left">&#x793A;&#x4F8B;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">DATE</td>
<td style="text-align:left">4</td>
<td style="text-align:left">&apos;2020-01-01&apos;</td>
</tr>
<tr>
<td style="text-align:left">TIME</td>
<td style="text-align:left">3</td>
<td style="text-align:left">&apos;12:29:59&apos;</td>
</tr>
<tr>
<td style="text-align:left">DATETIME</td>
<td style="text-align:left">8</td>
<td style="text-align:left">&apos;2020-01-01 12:29:59&apos;</td>
</tr>
<tr>
<td style="text-align:left">YEAR</td>
<td style="text-align:left">1</td>
<td style="text-align:left">&apos;2017&apos;</td>
</tr>
<tr>
<td style="text-align:left">TIMESTAMP</td>
<td style="text-align:left">4</td>
<td style="text-align:left">&apos;1970-01-01 00:00:01&apos; UTC ~ &apos;2038-01-01 00:00:01&apos; UTC</td>
</tr>
</tbody>
</table>
<h3 id="24-&#x5C0F;&#x7ED3;">2.4 &#x5C0F;&#x7ED3;</h3>
<ol>
<li>&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5F71;&#x54CD;&#x7740;&#x6570;&#x636E;&#x4E2D;&#x5B58;&#x50A8;&#x7684;&#x6570;&#x636E;&#x6240;&#x5360;&#x7684;&#x5BF9;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x6700;&#x57FA;&#x672C;&#x7684;&#x7C7B;&#x578B;&#x7EA6;&#x675F;&#x3001;&#x7A7A;&#x95F4;&#x5927;&#x5C0F;.</li>
<li>MySQL &#x6570;&#x636E;&#x5E93;&#x5E38;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5982;&#x4E0B;:<ul>
<li>&#x6574;&#x6570;: int&#xFF0C;bit</li>
<li>&#x5C0F;&#x6570;: decimal</li>
<li>&#x5B57;&#x7B26;&#x4E32;: varchar,char</li>
<li>&#x65E5;&#x671F;&#x65F6;&#x95F4;: date, time, datetime</li>
<li>&#x679A;&#x4E3E;&#x7C7B;&#x578B;: enum</li>
</ul>
</li>
<li>MySQL &#x4E2D;&#x5C3D;&#x91CF;&#x4F7F;&#x7528;&#x5360;&#x7528;&#x7A7A;&#x95F4;&#x8F83;&#x5C0F;&#x7684;&#x7C7B;&#x578B;.</li>
<li>MySQL &#x7EA6;&#x675F;&#x672C;&#x8D28;&#x4E0A;&#x662F;&#x5BF9;&#x6570;&#x636E;&#x5728;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x9650;&#x5B9A;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x6DFB;&#x52A0;&#x7684;&#x989D;&#x5916;&#x7684;&#x8981;&#x6C42;.</li>
<li>MySQL &#x6570;&#x636E;&#x5E93;&#x5E38;&#x89C1;&#x7EA6;&#x675F;&#x5982;&#x4E0B;:
 <em>. &#x4E3B;&#x952E; primary key: &#x7269;&#x7406;&#x4E0A;&#x5B58;&#x50A8;&#x7684;&#x987A;&#x5E8F;. 
 </em>. &#x975E;&#x7A7A; not null: &#x6B64;&#x5B57;&#x6BB5;&#x4E0D;&#x5141;&#x8BB8;&#x586B;&#x5199;&#x7A7A;&#x503C;.
 <em>. &#x60DF;&#x4E00; unique: &#x6B64;&#x5B57;&#x6BB5;&#x7684;&#x503C;&#x4E0D;&#x5141;&#x8BB8;&#x91CD;&#x590D;.
 </em>. &#x9ED8;&#x8BA4; default: &#x5F53;&#x4E0D;&#x586B;&#x5199;&#x5B57;&#x6BB5;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x4F1A;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x5982;&#x679C;&#x586B;&#x5199;&#x65F6;&#x4EE5;&#x586B;&#x5199;&#x4E3A;&#x51C6;.
 *. &#x5916;&#x952E; foreign key: &#x5BF9;&#x5173;&#x7CFB;&#x5B57;&#x6BB5;&#x8FDB;&#x884C;&#x7EA6;&#x675F;, &#x5F53;&#x4E3A;&#x5173;&#x7CFB;&#x5B57;&#x6BB5;&#x586B;&#x5199;&#x503C;&#x65F6;, &#x4F1A;&#x5230;&#x5173;&#x8054;&#x7684;&#x8868;&#x4E2D;&#x67E5;&#x8BE2;&#x6B64;&#x503C;&#x662F;&#x5426;&#x5B58;&#x5728;, &#x5982;&#x679C;&#x5B58;&#x5728;&#x5219;&#x586B;&#x5199;&#x6210;&#x529F;, &#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x586B;&#x5199;&#x5931;&#x8D25;&#x5E76;&#x629B;&#x51FA;&#x5F02;&#x5E38;.</li>
</ol>
<h2 id="25-&#x601D;&#x8003;">2.5 &#x601D;&#x8003;</h2>
<p>&#x5982;&#x679C;&#x6709;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;&#x6709;&#x8FD9;&#x6837;&#x7684;&#x4E00;&#x79CD;&#x5B8C;&#x6574;&#x6027;&#x8981;&#x6C42;, &#x8BF7;&#x8BF4;&#x660E;&#x542B;&#x4E49;:</p>
<pre><code>id int unsigned not null unique
</code></pre>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../day14/01.数据库概述.html" class="navigation navigation-prev " aria-label="Previous page: 数据库概述"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../day14/03.Navicat.html" class="navigation navigation-next " aria-label="Next page: 图形化客户端Navicat"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book python高级 -->
</html>
